/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package swym.server.io;

import java.util.*;
import java.io.*;

/**
 *
 * @author mschaefer
 */
public class FileUtilities
{
    public static Vector<String> readLines( String path ) throws IOException
    {
        Vector<String> lines = new Vector<String>();
    
        FileReader fileReader = null;
        BufferedReader bufferedReader = null;

        try
        {
            fileReader = new FileReader( new File( path ) );
            bufferedReader = new BufferedReader( fileReader );

            String line = bufferedReader.readLine();

            while (line != null)
            {
                lines.add( line );

                line = bufferedReader.readLine();
            }
            
            fileReader.close();

            return lines;
        }
        catch ( IOException e )
        {
            if ( fileReader != null )
                fileReader.close();
            
            throw e;
        }
        
    }
    
    public static void writeLines( String path, Vector<String> lines ) 
            throws IOException
    {
        FileOutputStream fileOutputStream = null;
        PrintStream filePrintStream = null;
        
        fileOutputStream = new FileOutputStream( new File( path ) );
        filePrintStream = new PrintStream( fileOutputStream );
        
        try
        {
            for ( String line : lines )
                filePrintStream.println( line );
            
            fileOutputStream.close();
        }
        catch ( IOException e )
        {
            if ( fileOutputStream != null )
                fileOutputStream.close();
            
            throw e;
        }
    }
}
